package juc.utils.phaser;

import java.util.concurrent.Phaser;
import java.util.concurrent.TimeUnit;

public class PhaserExample4 {
    public static void main(String[] args) throws InterruptedException {
        final Phaser phaser = new Phaser(1);

        //System.out.println(phaser.getPhase());
        //phaser.arriveAndAwaitAdvance();
        //System.out.println(phaser.getPhase());
        //phaser.arriveAndAwaitAdvance();
        //System.out.println(phaser.getPhase());
        //phaser.arriveAndAwaitAdvance();
        //System.out.println(phaser.getPhase());

        //System.out.println(phaser.getRegisteredParties());
        //phaser.register();
        //System.out.println(phaser.getRegisteredParties());
        //phaser.register();
        //System.out.println(phaser.getRegisteredParties());

        phaser.bulkRegister(10);
        System.out.println(phaser.getRegisteredParties());

        new Thread(phaser::arriveAndAwaitAdvance).start();
        TimeUnit.SECONDS.sleep(1);
        System.out.println(phaser.getArrivedParties());
        System.out.println(phaser.getUnarrivedParties());

    }

}
